﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Meraz.Core.Model
{
    public class Domain
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public Nullable<int> ParentID { get; set; }
        public List<Url> Urls { get; set; }
        public Domain Parent { get; set; }
        public List<Domain> SubDomains { get; set; }
        public string Ideology
        {
            get { return this.IdeologyType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.IdeologyType = IdeologyType.Undefined;
                else
                {
                    try
                    {
                        this.IdeologyType = (IdeologyType)Enum.Parse(typeof(IdeologyType), value);
                    }
                    catch
                    {
                        this.IdeologyType = IdeologyType.Undefined;
                    }
                }
            }
        }
        public IdeologyType IdeologyType { get; set; }
        public string Media
        {
            get { return this.MediaType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.MediaType = MediaType.Undefined;
                else
                {
                    try
                    {
                        this.MediaType = (MediaType)Enum.Parse(typeof(MediaType), value);
                    }
                    catch
                    {
                        this.MediaType = MediaType.Undefined;
                    }
                }
            }
        }
        public MediaType MediaType { get; set; }
        public string Organization
        {
            get { return this.PartyType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.OrganizationType = OrganizationType.Undefined;
                else
                {
                    try
                    {
                        this.OrganizationType = (OrganizationType)Enum.Parse(typeof(OrganizationType), value);
                    }
                    catch
                    {
                        this.OrganizationType = OrganizationType.Undefined;
                    }
                }
            }
        }
        public OrganizationType OrganizationType { get; set; }
        public string Party
        {
            get { return this.PartyType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.PartyType = PartyType.Undefined;
                else
                {
                    try
                    {
                        this.PartyType = (PartyType)Enum.Parse(typeof(PartyType), value);
                    }
                    catch
                    {
                        this.PartyType = PartyType.Undefined;
                    }
                }
            }
        }
        public PartyType PartyType { get; set; }
        public string Social
        {
            get { return this.SocialType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.SocialType = SocialType.Undefined;
                else
                {
                    try
                    {
                        this.SocialType = (SocialType)Enum.Parse(typeof(SocialType), value);
                    }
                    catch
                    {
                        this.SocialType = SocialType.Undefined;
                    }
                }
            }
        }
        public SocialType SocialType { get; set; }
        public string Theme
        {
            get { return this.ThemeType.ToString(); }
            set
            {
                if (string.IsNullOrWhiteSpace(value))
                    this.ThemeType = ThemeType.Undefined;
                else
                {
                    try
                    {
                        this.ThemeType = (ThemeType)Enum.Parse(typeof(ThemeType), value);
                    }
                    catch
                    {
                        this.ThemeType = ThemeType.Undefined;
                    }
                }
            }
        }
        public ThemeType ThemeType { get; set; }

        public string ToJavascriptArray()
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("[{0},", ID);
            builder.AppendFormat("'{0}'", Name);
            builder.AppendFormat("'{0}'", Ideology);
            builder.AppendFormat("'{0}'", Media);
            builder.AppendFormat("'{0}'", Organization);
            builder.AppendFormat("'{0}'", Party);
            builder.AppendFormat("'{0}'", Social);
            builder.AppendFormat("'{0}']", Theme);
            return builder.ToString();
        }
    }
}
